home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 June: Reference Library / Dev.CD Jun 96 RL / Dev.CD Jun 96 RL.toast / Technical Documentation / develop / develop Issue 24 / develop Issue 24 code / Scriptable Database 1.0a15 / Database / DBElement.h < prev    next >
Encoding:
Text File  |  1996-04-25  |  7.4 KB  |  200 lines  |  [TEXT/CWIE]

  1. //================================================================================
  2. // Greg Anderson
  3. // db+
  4. //
  5. // Cursor to an object record
  6. // 16 May 1994
  7. //================================================================================
  8. #pragma once
  9.  
  10. #ifndef __DBELEMENTRECORD__
  11. #define __DBELEMENTRECORD__
  12.  
  13. #include "DBRecord.h"
  14.  
  15. class TDBProperty;
  16.  
  17. //
  18. // An object record cursor contains elements and properties, both
  19. // stored in a balanced tree
  20. //
  21. // Fields:
  22. //
  23. //        Flags
  24. //            b31-b29:    Used by AbstractDBRecord
  25. //            b28:        Set = object record (Clear = some other type of record)
  26. //            b27-b0:     Node number
  27. //        Parent sibling (same as parent element for child at top of tree)
  28. //        Left sibling
  29. //        Right sibling
  30. //
  31. //        Parent element (cached location of TreeOwner)
  32. //        Child at top of element tree
  33. //        Data record at top of property tree
  34. //        Name property (cached location of pName in property tree)
  35. //
  36.  
  37. enum
  38. {
  39.     kParentElementWord = kIDOrParentElementIndex
  40. };
  41.  
  42. //
  43. // Well-known property IDs
  44. //
  45. enum
  46. {
  47.     //
  48.     // The "name" property happens to have the same value
  49.     // as 'pName' in AERegistry.h; however, I want to avoid
  50.     // Macintosh include files here, so I'm redefining
  51.     // the constant.
  52.     //
  53.     kNameProperty = 'pnam'
  54. };
  55.  
  56. //================================================================================
  57. // Class TDBElement
  58. //================================================================================
  59. class TDBElement : public TDBRecord
  60. {
  61.     //
  62.     // ----- Fields --------------------------------------------------------------
  63.     //
  64. protected:
  65.     
  66.     //
  67.     // ----- Methods -------------------------------------------------------------
  68.     //
  69.  
  70. public:
  71.                                     TDBElement(TDatabaseDocument* doc, long recordIndex) :
  72.                                         TDBRecord(doc, recordIndex) {};
  73.     virtual                            ~TDBElement();
  74.     
  75.     //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  76.     // Methods of TAbstractRecord:
  77.     //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  78.  
  79. protected:
  80.  
  81.     virtual const TDBElement*        DBElementRecord() const { return this; };
  82.  
  83.     //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  84.     // Methods of TDBRecord:
  85.     //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  86.  
  87. public:    
  88.  
  89.     virtual AConst<TDBRecord>        TreeOwner(TTransaction* t) const            { return this->ParentElement(t); }
  90.     virtual void                    InitializeNewRecord(TTransaction* t);
  91.     virtual void                    PropertyValueChanged(TTransaction* t, AConst<TDBProperty> propertyThatChanged);
  92.     virtual CompareEnumeration        CompareSortKeys(TTransaction* t, AConst<TDBRecord> secondObject) const;
  93.     virtual Boolean                    RecordCanHaveElements(TTransaction* t) const;
  94.     virtual Boolean                    RecordCanHaveProperties(TTransaction* t) const;
  95.     
  96.     //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  97.     // Public interface: const methods
  98.     //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  99.  
  100. public:
  101.  
  102.     long                            NodeNumber(TTransaction* t) const            { return this->RecordFlags(t) & kObjectRecordReservedRecordBits; };
  103.  
  104.     //
  105.     // Methods to look up properties and elements:
  106.     //
  107.     AConst<TDBProperty>                GetPropertyRecord(TTransaction* t, long propertyID) const;
  108.     AConst<TDBElement>                GetNamedElement(TTransaction* t, const TAbstractDataReference& nameSpec) const;
  109.  
  110.     //
  111.     // Methods to get values directly from a property of this object
  112.     //
  113.     long                            GetLongwordProperty(TTransaction* t, long propertyID) const;
  114. //    void                            GetStringProperty(TTransaction* t, long propertyID, CString& str, short maxLength) const;
  115.     Boolean                            GetBooleanProperty(TTransaction* t, long propertyID) const { return this->GetLongwordProperty(t, propertyID); };
  116.     void                            GetTypedProperty(TTransaction* t, long propertyID, TUpdataDataReference& data) const;
  117. //    void                            NameString(TTransaction* t, CString& objectsName, short maxLength) const;
  118.     
  119.     AConst<TDBElement>                ParentElement(TTransaction* t) const        { return this->GetDBElementCursor(this->ParentElementIndex(t)); };
  120.     AConst<TDBProperty>                NameProperty(TTransaction* t) const            { return this->GetDBPropertyCursor(this->NamePropertyIndex(t)); };
  121.  
  122.     //
  123.     // Methods that return the top record of the element / property tree
  124.     // (usually you should just use the routines above, though)
  125.     //
  126.     AConst<TDBElement>                Elements(TTransaction* t) const                { return this->GetDBElementCursor(this->TopChildIndex(t)); };
  127.     AConst<TDBProperty>                Properties(TTransaction* t) const            { return this->GetDBPropertyCursor(this->TopPropertyIndex(t)); };
  128.     
  129.     //
  130.     // Debugging:
  131.     //
  132.     virtual void                    Verify(TTransaction* t, Boolean verifyDeep = false) const;
  133.  
  134.     //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  135.     // Public interface: non-const methods
  136.     //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  137.  
  138. public:
  139.     
  140.     //
  141.     // Add an element or property to this element
  142.     //
  143.     void                            AddElement(TTransaction* t, AnUpdate<TDBElement> newElement);
  144.     void                            AddProperty(TTransaction* t, AnUpdate<TDBProperty> newProperty);
  145.     
  146.     //
  147.     // Directly change the value of a property of this element
  148.     //
  149.     void                            AddLongwordProperty(TTransaction* t, long propertyID, long newValue);
  150. //    void                            AddStringProperty(TTransaction* t, long propertyID, CString& name);
  151.     void                            AddBooleanProperty(TTransaction* t, long propertyID, Boolean newValue) { this->AddLongwordProperty(t, propertyID, newValue); };
  152.     void                            AddTypedProperty(TTransaction* t, long propertyID, const TAbstractDataReference& data);
  153.     
  154.     //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  155.     // Protected interface: const methods
  156.     //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  157.  
  158. protected:
  159.  
  160.     long                            ParentElementIndex(TTransaction* t) const    { return this->GetRecordData(t, kParentElementWord); };
  161.     long                            NamePropertyIndex(TTransaction* t) const    { return this->GetRecordData(t, kNamePropertyWord); };
  162.     
  163.     //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  164.     // Protected interface: non-const methods
  165.     //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  166.  
  167. protected:
  168.  
  169.     AConst<TDBProperty>                GetPropertyRecordForceCreate(TTransaction* t, long propertyID);
  170.  
  171.     void                            SetNodeNumber(TTransaction* t, long newValue)            { this->SetRecordFlags(t, (newValue & kObjectRecordReservedRecordBits) | (this->RecordFlags(t) & ~kObjectRecordReservedRecordBits)); };
  172.     void                            SetParentElementIndex(TTransaction* t, long newValue)    { this->ChangeRecordData(t, kParentElementWord, newValue); };
  173.     void                            SetNamePropertyIndex(TTransaction* t, long newValue)        { this->ChangeRecordData(t, kNamePropertyWord, newValue); };
  174.     
  175.     void                            SetParentElement(TTransaction* t, AConst<TDBElement> parentElement) { this->SetParentElementIndex(t, parentElement->RecordIndex()); }
  176.     
  177.     //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  178.     // Private methods:
  179.     //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  180.  
  181. private:
  182.         
  183. };
  184.  
  185. //================================================================================
  186. // Class TObjectRecordComparisonObject
  187. //================================================================================
  188. class TObjectRecordComparisonObject : public TAbstractDBComparisonObject
  189. {
  190. private:
  191.     const TAbstractDataReference&    fSearchKey;
  192.     
  193. public:
  194.                                     TObjectRecordComparisonObject(const TAbstractDataReference& searchKey) : fSearchKey(searchKey) {};
  195.  
  196.     virtual CompareEnumeration        TestObject(TTransaction* t, AConst<TDBRecord>);
  197. };
  198.  
  199. #endif
  200.